﻿using System;
using System.Reflection;
using Autodesk.Revit.DB;

namespace FetchDataCompare
{
	internal class GeoObjectStructFactory
	{
		public GeoObjectStructFactory()
		{
			GeoObjectStructFactory.m_Assembly = Assembly.GetAssembly(typeof(WireGeoObj));
		}

		public static GeoObjectStructBase CreateGeoObjectIns(Element element, Autodesk.Revit.DB.View view)
		{
			GeoObjectStructBase geoObjectStructBase = null;
			XMLOperator xmloperator = new XMLOperator();
			string text = element.GetType().ToString();
			string xpath = string.Concat(new object[]
			{
				"/root/",
				element.Category.Id.IntegerValue,
				"/",
				text.Substring(text.LastIndexOf('.') + 1, text.Length - text.LastIndexOf('.') - 1)
			});
			try
			{
				string typeName = "FetchDataCompare." + xmloperator.GetGeoObjectStructType(xpath);
				geoObjectStructBase = (GeoObjectStructFactory.m_Assembly.CreateInstance(typeName) as GeoObjectStructBase);
				geoObjectStructBase.UseElement = element;
				geoObjectStructBase.UseView = view;
				geoObjectStructBase.InitGeoObj();
				geoObjectStructBase.Attribute = geoObjectStructBase.GetElementAttribute();
			}
			catch (Exception)
			{
				geoObjectStructBase = new GeoCommonStruct();
				geoObjectStructBase.UseElement = element;
				geoObjectStructBase.UseView = view;
				geoObjectStructBase.InitGeoObj();
			}
			return geoObjectStructBase;
		}

		private static Assembly m_Assembly = Assembly.GetAssembly(typeof(WireGeoObj));
	}
}
